package com.example.ya11_16;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;


public class MyPhoneService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
    @Override
    public void onCreate() {
        TelephonyManager telephonyManager= (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        telephonyManager.listen(new PhoneStateListener(),PhoneStateListener.LISTEN_CALL_STATE);
    }
    class MyFirstService extends PhoneStateListener{
        @Override
        public void onCallStateChanged(int state, String phoneNumber) {
            switch (state){
                case TelephonyManager.CALL_STATE_OFFHOOK:
                    break;
                case TelephonyManager.CALL_STATE_RINGING:
                    System.out.println("来电状态"+state);
                    System.out.println("来电号码"+phoneNumber);
                    if ("5556".equals(phoneNumber)){
                        System.out.println("挂断电话。。");
                    }
                    break;
            }
        }
    }
}
